<template>
  <div class="block">
    <div class="flex-center none-collection" v-if="colList === null || colList.length === 0">
      <div class="oh">
        <div class="icon">
          <i class="fa fa-heartbeat"></i>
        </div>
        <div class="txt">亲，您还没有任何收藏哦，请点击下面按钮<br><router-link :to="{path: '/goodsList'}">先逛一会儿</router-link></div>
      </div>
    </div>
    <div class="col-list flex-center-top" v-else v-for="(item, ind) in colList" :key="ind">
      <div class="col-list-img">
        <img :src="apiUrl + item.goodsLogo" alt="">
      </div>
      <div class="flex-col col-list-main">
        <div class="title">{{ item.goodsName }}</div>
        <div class="price">
          <span class="now">&yen;{{ item.goodsPrice }}</span>
          <span>&yen;{{ item.marketPrice }}</span>
        </div>
        <span class="del-collection" @click="delCollection(item.goodsId)">
          <i class="fa fa-heart"></i>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import { MessageBox } from 'mint-ui';
import { Toast } from 'mint-ui';

export default {
  data () {
    return {
      apiUrl: 'http://app.wodinghua.com',
      colList: []
    }
  },
  mounted () {
    var localColList = JSON.parse(this.getItemStorange("goodsCollections"));
    this.colList = localColList;
    console.log(this.colList);
  },
  methods: {
    delCollection (id) {
      MessageBox.confirm('你确定删除此收藏？').then(action => {
        if (action == 'confirm') {
          for(var i = 0; i < this.colList.length; i++) {
            var gId = parseInt(this.colList[i].goodsId);
            if(parseInt(id) === gId) {
              this.colList.splice(i, 1);
              this.setItemStorange("goodsCollections", JSON.stringify(this.colList));
              Toast('删除成功');
              break;
            }
          }
        }
      }).catch(err => {
        if (err == 'cancel') {
          Toast('您已取消');
        }
      });
      
    }
  }
}
</script>

<style scoped lang="less">
  @import url('../../../static/var');

  .block {
    height: 100%;
  }
  .none-collection {
    height: 100%;
    text-align: center;
    .fa {
      font-size: 50px;
      color: @col-c8;
    }
    .txt {
      font-size: @f12;
      margin: 10px;
      a {
        margin-top: 15px;
        display: inline-block;
        text-decoration: none;
        padding: 7px 15px 6px;
        background-color: @col-blue;
        color: @bg-col-fff;
        border-radius: 5px;
      }
    }
  }
  .col-list {
    padding: 15px;
    background-color: #fff;
    background-image: -webkit-linear-gradient(top, @col-e2, @col-e2 50%, transparent 50%);
    background-image: linear-gradient(180deg, @col-e2, @col-e2 50%, transparent 50%);
    background-size: 120% 1px;
    background-repeat: no-repeat;
    background-position: bottom left;
  }
  .col-list-img {
    width: 80px;
    height: 80px;
    overflow: hidden;
    margin-right: 15px;
  }
  .col-list-main {
    position: relative;
    .title {
      font-size: @f14;
    }
    .price {
      margin-top: 10px;
      span {
        text-decoration: line-through;
        color: @col-92;
        &.now {
          color: @col-orange;
          text-decoration: none;
          margin-right: 10px;
        }
      }
    }
    .del-collection {
      display: inline-block;
      .box(30px, 30px);
      .position(absolute, auto, 0, 0, auto);
      z-index: 100;
      i {
        float: left;
        font-size: @f18;
        color: @col-orange;
        margin-top: 12px;
        margin-left: 12px;
      }
    }
  }
</style>